home *** CD-ROM | disk | FTP | other *** search
/ PC Open 100 / PC Open 100 CD 2.bin / CD2 / Demo / website plus / programma / RESFiles.001 / engine.js next >
Encoding:
Text File  |  2003-09-08  |  14.2 KB  |  525 lines

  1. // menu creation
  2. NS=(document.layers) ? true : false;
  3. IE=(document.all) ? true : false;
  4. IE50=(navigator.appVersion.indexOf("MSIE 5.0")!=-1?true:false);
  5. function popUp(){return};
  6. function popDown(){return};
  7. areCreated=false;
  8.  
  9. mSecsVis = secondsVisible*1000;
  10.  
  11. // layers settings
  12. semi = ";";
  13. styleStr = "<STYLE TYPE='text/css'>"
  14. styleStr += ".items {"
  15. styleStr += "width:" + menuWidth + semi
  16. styleStr += "color:"+ fntCol + semi
  17. styleStr += "font-size:"+ fntSiz + semi
  18. styleStr += "font-style:"+ fntSty + semi
  19. styleStr += "font-family:"+ fntFam + semi
  20. styleStr += "font-weight:"+ fntWeight + semi
  21. styleStr += "border-width:" + borWid + semi
  22. styleStr += "border-color:" + borCol + semi
  23. styleStr += "border-style: solid" + semi
  24. styleStr += "filter: progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")" + semi
  25. styleStr += "}"
  26. styleStr += "</STYLE>";
  27. document.write(styleStr);
  28.  
  29. // image settings
  30. if (imgSrc !="") imgStr = "<IMG SRC=" + imgSrc + " BORDER=0 VSPACE=3 WIDHT=7 HEIGHT=7 ALIGN=RIGHT>" 
  31. else imgStr = ""
  32.  
  33. topCount = 1;
  34. areCreated = false;
  35. isOverMenu = false;
  36. currentMenu = null;
  37. allTimer = null;
  38.  
  39. function menuSetup(hasParent,lastItem,openCont,openItem) {
  40.     this.menuOver = menuOver;
  41.     this.menuOut = menuOut;
  42.     this.onmouseover = this.menuOver;
  43.     this.onmouseout = this.menuOut;
  44.     this.showIt = showIt;
  45.     this.keepInWindow = keepInWindow;
  46.     this.hideTree = hideTree
  47.     this.hideParents = hideParents;
  48.     this.hideChildren = hideChildren;
  49.     this.hideTop = hideTop;
  50.     this.hasChildVisible = false;
  51.     this.isOn = false;
  52.     this.hideTimer = null;
  53.  
  54.     if (hasParent) {
  55.         this.hasParent = true;
  56.         this.parentMenu = openCont;
  57.         this.parentItem = openItem;
  58.         this.parentItem.child = this;
  59.     }
  60.     else {
  61.         this.hasParent = false;
  62.         this.hideSelf = hideSelf;
  63.     }
  64.  
  65.     if (NS) {
  66.         this.fullHeight = lastItem.top + lastItem.document.height;
  67.         this.clip.bottom = this.fullHeight;
  68.     }
  69.     else {
  70.         this.fullHeight = lastItem.style.pixelTop + lastItem.offsetHeight;
  71.         this.showIt(false);
  72.         this.onselectstart = cancelSelect;
  73.         this.moveTo = moveTo;
  74.         this.moveTo(0,0);
  75.     }
  76. }
  77. function itemSetup(arrayPointer,whichArray) {
  78.     this.itemOver = itemOver;
  79.     this.itemOut = itemOut;
  80.     this.onmouseover = this.itemOver;
  81.     this.onmouseout = this.itemOut;
  82.     this.dispText = whichArray[arrayPointer];
  83.     this.linkText = whichArray[arrayPointer + 1];
  84.     this.hasMore = whichArray[arrayPointer + 2];
  85.  
  86.     if (this.linkText.length > 0) {
  87.         this.linkIt = linkIt;
  88.         if (NS) {
  89.             this.onfocus = this.linkIt;
  90.         }
  91.         else {
  92.             this.onclick = this.linkIt;
  93.             this.style.cursor = "hand";
  94.         }
  95.     }
  96.       
  97.     if (this.hasMore) {
  98.         htmStr = imgStr + this.dispText;
  99.     }
  100.     else {
  101.         htmStr = this.dispText;
  102.     }
  103.  
  104.     if (NS) {
  105.         layStr = "<SPAN CLASS=items>" + htmStr+ "</SPAN>";
  106.         this.document.write(layStr);
  107.         this.document.close();
  108.         this.bgColor = backCol;
  109.         this.clip.right = menuWidth;
  110.         this.visibility = "inherit";
  111.         this.container = this.parentLayer;
  112.  
  113.         if (arrayPointer == 0) {
  114.             this.top = 0;
  115.         }
  116.         else {
  117.             this.top = this.prevItem.top + this.prevItem.document.height - borWid;
  118.         }
  119.         this.left = 0;
  120.     }
  121.     else {
  122.         this.className = "items";
  123.         this.style.padding = 3;
  124.         this.innerHTML = htmStr;
  125.  
  126.         this.style.backgroundColor = backCol; 
  127.         this.container = this.offsetParent;
  128.  
  129.         if (arrayPointer == 0) {
  130.             this.style.pixelTop = 0;
  131.         }
  132.         else {
  133.             this.style.pixelTop = this.prevItem.style.pixelTop + this.prevItem.offsetHeight - borWid;
  134.         }
  135.         this.style.pixelLeft = 0;
  136.     }
  137. }
  138. function makeElement(whichEl,whichContainer) {
  139.     if (arguments.length==1)
  140.         whichContainer = (NS) ? window : document.body;
  141.  
  142.     if (NS) {
  143.         eval(whichEl + "= new Layer(menuWidth,whichContainer)");
  144.     }
  145.     else {
  146.         elStr = "<DIV ID=" + whichEl + " STYLE='position:absolute'></DIV>";
  147.         whichContainer.insertAdjacentHTML("BeforeEnd",elStr);
  148.     }
  149.  
  150.     return eval(whichEl);
  151. }
  152. function makeTop() {
  153.     while(eval("window.arMenu" + topCount)) {
  154.         topArray = eval("arMenu" + topCount);
  155.         topName = "elMenu" + topCount;
  156.         topMenu = makeElement(topName);
  157.             topMenu.setup = menuSetup;
  158.  
  159.         topItemCount = 0;
  160.         for (i=0; i<topArray.length; i+=3) {
  161.             topItemCount++;
  162.             topItemName = "item" + topCount + "_" + topItemCount;
  163.             topItem = makeElement(topItemName,topMenu);
  164.  
  165.             if (topItemCount >1)
  166.                 topItem.prevItem = eval("item" + topCount + "_" + (topItemCount-1));
  167.  
  168.             topItem.setup = itemSetup;
  169.             topItem.setup(i,topArray);
  170.  
  171.             if (topItem.hasMore) makeSecond();
  172.         }
  173.         topMenu.setup(false,topItem);
  174.         topCount++
  175.     }
  176.     areCreated = true;
  177. }
  178. function makeSecond() {
  179.     secondCount = topCount + "_" + topItemCount;
  180.     secondArray = eval("arMenu" + secondCount);
  181.     secondName = "elChild" + secondCount;
  182.     secondMenu = makeElement(secondName);
  183.     secondMenu.setup = menuSetup;
  184.  
  185.     secondItemCount=0;
  186.     for (j=0; j<secondArray.length; j+=3) {
  187.         secondItemCount++;
  188.         secondItemName = "item" + secondCount +"_" + secondItemCount;
  189.  
  190.         secondItem = makeElement(secondItemName,secondMenu)        
  191.         
  192.         if (secondItemCount >1)
  193.             secondItem.prevItem = eval("item" + secondCount  + "_" + (secondItemCount-1));
  194.  
  195.         secondItem.setup = itemSetup;
  196.         secondItem.setup(j,secondArray);
  197.  
  198.         if (secondItem.hasMore) makeThird();
  199.     }
  200.     secondMenu.setup(true,secondItem,topMenu,topItem);
  201. }
  202. function makeThird() {
  203.     thirdCounter = secondCount + "_" + secondItemCount 
  204.     thirdArray = eval("arMenu" + thirdCounter);
  205.     thirdName = "elGrandChild" + thirdCounter;
  206.     thirdMenu = makeElement(thirdName)
  207.     thirdMenu.setup = menuSetup;
  208.  
  209.     thirdItemCount=0;
  210.     for (k=0; k<thirdArray.length; k+=3) {
  211.         thirdItemCount++;
  212.         thirdItemName = "item" + thirdCounter + "_" + thirdItemCount;
  213.         thirdItem = makeElement(thirdItemName,thirdMenu);
  214.  
  215.         if (thirdItemCount >1)
  216.             thirdItem.prevItem = eval("item" + thirdCounter + "_" +(thirdItemCount-1));
  217.  
  218.         thirdItem.setup = itemSetup;
  219.         thirdItem.setup(k,thirdArray);
  220.     }
  221.     thirdMenu.setup(true,thirdItem,secondMenu,secondItem);
  222. }
  223. function linkIt() {
  224.     location.href = this.linkText;
  225. }
  226. function showIt(on) {
  227.     if (NS) {this.visibility = (on) ? "show" : "hide"}
  228.         else {this.style.visibility = (on) ? "visible" : "hidden"}
  229. }
  230. function keepInWindow() {
  231.     scrBars = 20;
  232.     if (NS) {
  233.         winRight = (window.pageXOffset + window.innerWidth) - scrBars;
  234.         rightPos = this.left + menuWidth;
  235.    
  236.         if (rightPos > winRight) {
  237.             if (this.hasParent) {
  238.                 parentLeft = this.parentMenu.left;
  239.                 newLeft = ((parentLeft-menuWidth) + childOverLeft);
  240.                 this.left = newLeft;
  241.             }
  242.             else {
  243.                 dif = rightPos - winRight;
  244.                 this.left -= dif;
  245.             }
  246.         }
  247.         winBot = (window.pageYOffset + window.innerHeight) - scrBars;
  248.         botPos = this.top + this.fullHeight;
  249.  
  250.         if (botPos > winBot) {
  251.             dif = botPos - winBot;
  252.             this.top -= dif;
  253.         }
  254.     }
  255.     else {
  256.         winRight = (document.body.scrollLeft + document.body.clientWidth) - scrBars;
  257.         rightPos = this.style.pixelLeft + menuWidth;
  258.     
  259.         if (rightPos > winRight) {
  260.             if (this.hasParent) {
  261.                 parentLeft = this.parentMenu.style.pixelLeft;
  262.                 newLeft = ((parentLeft - menuWidth) + childOverLeft);
  263.                 this.style.pixelLeft = newLeft;
  264.             }
  265.             else {
  266.                 dif = rightPos - winRight;
  267.                 this.style.pixelLeft -= dif;
  268.             }
  269.         }
  270.         winBot = (document.body.scrollTop + document.body.clientHeight) - scrBars;
  271.         botPos = this.style.pixelTop + this.fullHeight;
  272.  
  273.         if (botPos > winBot) {
  274.             dif = botPos - winBot;
  275.             this.style.pixelTop -= dif;
  276.         }
  277.     }
  278. }
  279. function popUp(menuName,e){
  280.     if (!areCreated) return;
  281.  
  282.     hideAll();
  283.     currentMenu = eval(menuName);
  284.  
  285.     if (NS) {
  286.         xPos = e.pageX;
  287.         yPos = e.pageY;
  288.     }
  289.     else  {
  290.         if (menuType == 1) {
  291.               xPos = document.all["ID_" + menuName].offsetLeft;
  292.              yPos = document.all["ID_" + menuName].offsetTop + document.all["ID_" + menuName].offsetHeight;
  293.         }
  294.         else  {
  295.               xPos = document.all["ID_" + menuName].offsetLeft + document.all["ID_" + menuName].offsetWidth - childOverLeft + 1;
  296.              yPos = document.all["ID_" + menuName].offsetTop + childOverTop;
  297.         }
  298.  
  299.         document.all["ID_" + menuName].style.backgroundColor = overCol;
  300.         document.all["ID_" + menuName].style.color = fntOverCol;
  301.     }
  302.  
  303.     currentMenu.moveTo(xPos,yPos);
  304.     currentMenu.keepInWindow()
  305.     currentMenu.isOn = true;
  306.     currentMenu.showIt(true);
  307. }
  308. function popDown(menuName){ 
  309.     if (!areCreated) return;
  310.     whichEl = eval(menuName);
  311.     whichEl.isOn = false;
  312.     whichEl.hideTop();
  313.  
  314.     if (!NS){
  315.         document.all["ID_" + menuName].style.backgroundColor = backCol;
  316.         document.all["ID_" + menuName].style.color = fntCol;
  317.     }
  318. }
  319. function menuOver() {
  320.     this.isOn = true;
  321.     isOverMenu = true;
  322.     currentMenu = this;
  323.     if (this.hideTimer) clearTimeout(this.hideTimer);
  324. }
  325. function menuOut() {
  326.     if (IE && event.srcElement.contains(event.toElement)) return;
  327.     this.isOn = false;
  328.     isOverMenu = false;
  329.     if (IE) allTimer = setTimeout("currentMenu.hideTree()",10); 
  330. }
  331. function itemOver(){
  332.     if (IE && event.srcElement.tagName == "IMG") return;
  333.  
  334.     if (NS) {
  335.         this.bgColor = overCol;
  336.     }
  337.     else {
  338.         this.style.backgroundColor = overCol;
  339.         this.style.color = fntOverCol;
  340.     }
  341.     
  342.     if (this.container.hasChildVisible) {
  343.         this.container.hideChildren(this);
  344.     }            
  345.  
  346.     if(this.hasMore) {
  347.         if (NS) {
  348.             this.childX = this.container.left + (menuWidth - childOverLeft);
  349.             this.childY = this.pageY + childOverTop;
  350.         }
  351.         else {
  352.             this.childX = this.container.style.pixelLeft + (menuWidth - childOverLeft);
  353.             this.childY = this.style.pixelTop + this.container.style.pixelTop + childOverTop;
  354.         }
  355.  
  356.         this.child.moveTo(this.childX,this.childY);
  357.         this.child.keepInWindow();
  358.         this.container.hasChildVisible = true;
  359.         this.container.visibleChild = this.child;
  360.         this.child.showIt(true);
  361.     }
  362. }
  363. function itemOut() {
  364.     if (IE && (event.srcElement.contains(event.toElement)
  365.      || (event.fromElement.tagName=="IMG" && event.toElement.contains(event.fromElement))))
  366.         return;
  367.  
  368.     if (NS) {
  369.         this.bgColor = backCol;
  370.         if (!isOverMenu) {
  371.             allTimer = setTimeout("currentMenu.hideTree()",10);
  372.         }
  373.     }
  374.     else {
  375.         this.style.backgroundColor = backCol;
  376.         this.style.color = fntCol;
  377.     }
  378. }
  379. function hideAll() {
  380.     for(i=1; i<topCount; i++) {
  381.         temp = eval("elMenu" + i);
  382.         temp.isOn = false;
  383.         if (temp.hasChildVisible) temp.hideChildren();
  384.         temp.showIt(false);
  385.     }    
  386. }
  387. function hideTree() { 
  388.     allTimer = null;
  389.     if (isOverMenu) return;
  390.     if (this.hasChildVisible) {
  391.         this.hideChildren();
  392.     }
  393.     this.hideParents();
  394. }
  395. function hideChildren(item) {
  396.     if (this.visibleChild.hasChildVisible) {
  397.         this.visibleChild.visibleChild.showIt(false);
  398.         this.visibleChild.hasChildVisible = false;
  399.     }
  400.  
  401.     if (!this.isOn || !item.hasMore || this.visibleChild != this.child) {
  402.         this.visibleChild.showIt(false);
  403.         this.hasChildVisible = false;
  404.     }
  405. }
  406. function hideParents() {     
  407.     if (this.hasParent) {
  408.         this.showIt(false);
  409.         if (this.parentMenu.hasParent) {
  410.             this.parentMenu.isOn = false;        
  411.             this.parentMenu.showIt(false);
  412.             this.parentMenu.parentMenu.isOn = false;
  413.             whichEl = this.parentMenu.parentMenu
  414.         }
  415.         else {
  416.             this.parentMenu.isOn = false;
  417.             whichEl = this.parentMenu;
  418.         }
  419.     }
  420.     else {
  421.         whichEl = this;
  422.     }
  423.     whichEl.hideTop();
  424. }
  425. function hideTop() {
  426.     whichEl = this;
  427.     this.hideTimer = setTimeout("whichEl.hideSelf()",mSecsVis);
  428. }
  429. function hideSelf() {
  430.     this.hideTimer = null;
  431.     if (!this.isOn && !isOverMenu) { 
  432.         this.showIt(false);
  433.     }
  434. }
  435. function cancelSelect(){return false}
  436.  
  437. function moveTo(xPos,yPos) {
  438.     this.style.pixelLeft = xPos;
  439.     this.style.pixelTop = yPos;
  440. }
  441. window.onload = makeTop;
  442.  
  443. // First Level Items MouseOver Style
  444. function chgPageStl(OverStyle,divID) {
  445.     if (!NS){
  446.         if (OverStyle==1){
  447.             hideAll();
  448.             document.all["ID_elPage" + divID].style.backgroundColor = overCol;
  449.             document.all["ID_elPage" + divID].style.color = fntOverCol;
  450.         }
  451.         else {
  452.             document.all["ID_elPage" + divID].style.backgroundColor = backCol;
  453.             document.all["ID_elPage" + divID].style.color = fntCol;
  454.         }
  455.     }
  456. }
  457.  
  458. // Link Description
  459. // Code by Stefano Ranfagni. All rights reserved.
  460. function ViewTip(Txt,backgColor,textColor,borderdColor,textSize,doFadeFlag) {
  461. HideTip();
  462. buf="<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2 BGCOLOR=" + backgColor +" style=\"border: 1px solid " + borderdColor + "\"><TR><TD><FONT FACE=\"Tahoma, Arial\" SIZE=" + textSize + " COLOR=" + textColor + ">" + Txt + "</FONT></TD></TR></TABLE>";
  463. document.all.imToolTip.innerHTML = buf;
  464. document.all.imToolTip.style.left=event.x;
  465. document.all.imToolTip.style.top=event.y + 15;
  466. document.all.imToolTip.style.visibility="visible";
  467. fadeStep=0
  468. if (doFadeFlag) doFade();
  469. }
  470. function HideTip() {
  471. document.all.imToolTip.style.visibility="hidden";
  472. if (typeof oTime !== 'undefined') clearTimeout(oTime);
  473. document.all.imToolTip.style.filter="alpha(opacity=100)";
  474. }
  475. function doFade(){
  476. if (fadeStep<=100){
  477.     fadeStep+=15;
  478.     document.all.imToolTip.style.filter="alpha(opacity=" + fadeStep + ")";
  479.     oTime=setTimeout('doFade()', 50);
  480.     }
  481. }
  482.  
  483. // PopUpWindows
  484. // Code by Stefano Ranfagni. All rights reserved.
  485. function popUpWin(page,w,h,sb){
  486. l=(screen.width)?(screen.width-w)/2:100;
  487. t=(screen.height)?(screen.height-h)/2:100;
  488. prop='width='+ w + ',height='+ h + ',top=' + t + ',left=' + l + ',scrollbars='+ sb +',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  489. popUpWinWindow=window.open('','',prop);
  490. popUpWinWindow.focus();
  491. popUpWinWindow.location=page;
  492. }
  493.  
  494. // SlideShow
  495. // Code by Stefano Ranfagni. All rights reserved.
  496. var iLastSlide
  497. var iCount=1;
  498. var iAutoDelay
  499. function doTrans(iStep, iLast, bPosition){
  500.     iCount=(bPosition == 1)? iStep : iCount=iCount+iStep;
  501.     if (iCount == iLast+1) iCount=1;
  502.     if (iCount == 0) iCount=iLast;
  503.     if (IE50 == false) div_Main.filters.item(0).Apply();
  504.     sContent="<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\" HEIGHT=\"100%\"><TR><TD WIDTH=\"100%\"><CENTER>" + "<IMG SRC=\"" + document.all["img_" + iCount].src + "\" BORDER=\"0\">" + "</CENTER></TD></TR></TABLE>";
  505.     div_Main.innerHTML=sContent;
  506.     if (IE50 == false) div_Main.filters.item(0).Play();
  507. }
  508. function doAuto(){
  509.     doTrans(1,iLastSlide,0);
  510.     oTime=setTimeout('doAuto()', iAutoDelay);
  511. }
  512. function PlayStop(iLast,iDelay,sPlay,sStop){
  513.     iLastSlide=iLast;
  514.     iAutoDelay=iDelay*1000;
  515.     if (cmd_Auto.value == sStop) {
  516.         cmd_Auto.value=sPlay;
  517.         clearTimeout(oTime);
  518.     }
  519.     else {
  520.         cmd_Auto.value=sStop;
  521.         doTrans(1,iLastSlide,0);
  522.         oTime=setTimeout('doAuto()', iAutoDelay);
  523.     }
  524. }
  525.